package com.shigu.activity.action;

import com.shigu.activity.api.ActivityGoodsService;
import com.shigu.activity.bo.ActivityGoodsListRequest;
import com.shigu.activity.vo.ActivityGoodsListVo;
import com.shigu.exceptions.WapException;
import com.shigu.user.service.MallTokenService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("wapsjson")
public class ActivityGoodsController {

    @Resource(name = "activityGoodsServiceImpl")
    ActivityGoodsService activityGoodsService;
    @Autowired
    MallTokenService mallTokenService;

    @RequestMapping("getActivityGoodsList")
    @ResponseBody
    public ActivityGoodsListVo getActivityGoodsList(ActivityGoodsListRequest request) throws WapException {
        Long mallUserId;
        if(StringUtils.isNotBlank(request.getToken())){
            mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        }else{
            mallUserId = null;
        }
        return activityGoodsService.getActivityGoodsList(Long.valueOf(request.getaId())
                ,mallUserId,request.getPage(),request.getSize(),request.getVersion(),request.getOs()).success();
    }
}
